package hot100.h0912;
/**
  * @description 验证回文串
  * @author 不知名帅哥
  * @date 2024/9/12 21:47
  * @version 1.0
*/
public class JudgePalindrome {
    public static void main(String[] args) {

    }
    public boolean isPalindrome(String s) {
//         s = s.replaceAll("[^a-zA-Z0-9]", "");
         int left=0;
         int right=s.length()-1;
         s=s.toLowerCase();
         while (left<=right){
             char c = s.charAt(left);
             char d = s.charAt(right);
             if (Character.isLetterOrDigit(c)&&Character.isLetterOrDigit(d)){
                 if (c != d){
                     return false;
                 }
                 left++;
                 right--;
             }else if (Character.isLetterOrDigit(d)){
                 left++;
             }else if (Character.isLetterOrDigit(c)){
                 right--;
             }else {
                 left++;
                 right--;
             }
         }
         return true;
    }
}
